<include file='public/_meta'>
<title>终端列表</title>
<body>

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 智能设备 <span class="c-gray en">&gt;</span> 终端列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
			<div class="text-c" id="search_down"> 添加日期：
				<input type="text" onfocus="WdatePicker({ maxDate:'#F{ $dp.$D(\'datemax\')||\'%y-%M-%d\' }' })" id="datemin" class="input-text Wdate" style="width:100px;">
				-
				<input type="text" onfocus="WdatePicker({ minDate:'#F{ $dp.$D(\'datemin\') }',maxDate:'%y-%M-%d' })" id="datemax" class="input-text Wdate" style="width:100px;">
				<input type="text" class="input-text" style="width:250px" placeholder="ICCID卡号、卡号、智能设备号..." id="search_inpute" >
                <span class="select-box" style="width:96px;">
                    <select class="select" name="supplier_no" id="supplier_no" size="1">
                        <option value="" style="color: #429842;">车机厂商</option>
                        <option value="1376920002">赛卡</option>
                        <option value="1376920001">唯特迅</option>
                    </select>
                </span>
                <span class="select-box" style="width:96px;">
                    <select class="select" name="supplier_no" id="status" size="1">
                        <option value="" style="color: #429842;">注册状态</option>
                        <option value="1">已注册</option>
                        <option value="2">未注册</option>
                    </select>
                </span>
				<button type="submit" class="btn btn-success radius" id="search_btn"><i class="Hui-iconfont">&#xe665;</i> 搜索</button>		
			</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20"><span class="l"> <a class="btn btn-primary radius" onclick="register('批量注册')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 批量注册</a></span> <span class="ml-5"> <a class="btn btn-primary radius" onclick="member_add('添加设备','{:url('index/terminal/add')}','','550')" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 批量查询</a></span>  <span class="ml-5"> <a class="btn btn-success radius" onclick="excel_data_add('excel导入','{:url('index/terminal/excel_data')}','','310')" href="javascript:;"><i class="Hui-iconfont">&#xe645;</i> EXCEL导入</a></span> <span class="ml-5"> <a class="btn btn-warning radius" onclick="excel_data_out('导出excel','{:url('index/excell/terminal')}','','310')" href="javascript:;"><i class="Hui-iconfont">&#xe644;</i> 导出EXCEL</a></span>  </div>
	<div class="mt-20">
		<table class="table table-border table-bordered table-bg table-hover table-sort">
			<thead>
				<tr class="text-c">
					<th width="25"><input type="checkbox" name="" value=""></th>
					<th width="40">ID</th>
					<th width="">卡号</th>
					<th width="">卡序列号</th>
					<th width="">智能设备号</th>
					<th width="">车机厂商</th>
					<th width="120">添加时间</th>
					<th width="120">修改日期</th>
					<th width="60">状态</th>
					<th width="100">操作</th>
				</tr>
			</thead>
			<tbody>
				
			</tbody>
		</table>
	</div>
</div>
<!--_footer 作为公共模版分离出去-->
<include file='public/_footer'>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__PUBLIC__/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="__PUBLIC__/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
$(function(){
	var table = $('.table-sort').DataTable({
		"aaSorting": [[ 0, "desc" ]],//默认第几个排序
		// "bStateSave": true,//状态保存
		 searching: false,
		"aoColumnDefs": [
		  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
		  {"orderable":false,"aTargets":[0,1,2,3,4,5,6,7,8,9]}// 制定列不参与排序
		],
		"bProcessing" : true, //开启读取服务器数据时显示正在加载中……特别是大数据量的时候，开启此功能比较好  
        "bServerSide" : true,//服务器处理分页，默认是false，需要服务器处理，必须true  
        "ajax": {
		    "url": "{:url('index/terminal/index')}",
		    "type": "POST",
		    "data":{
		    	'datemin':$('#datemin').val(),
	    		'datemax':$('#datemax').val(),
		    	'search_inpute':$('#search_inpute').val()
		    }
	  	},
	  	displayLength: 10,
	  	columns: [
	  	{ data: 'id',render:data=>{
            return '<input type="checkbox" value="'+data+'" name="register">';
            } 
        },
        { data: 'id' },
        { data: 'cardcode' },
        { data: 'sim_id' },
        { data: 'equipment_id' },
    	{ data:'supplier_no',render:data=>{
    			switch (data) {
			        case 1376920002:
			        data = '赛卡(博鹭途)';     
			            break;
			        case 1376920001:
			        data = '唯特迅';     
			            break;
			        default:
			        data = '未知';   
			            break;
			    }
			   
	        	return data;
    		} 
    	},
        { data: 'create_time' },
        { data: 'update_time'},
        {className: "td-status",data: 'status',render:data=>{
        		if(data == 1){
        			return '<span class="label label-success radius">已注册</span>';
        		}else{
        			return '<span class="label radius">未注册</span>';
        		}
        		
        	}
    	},
        { className: "td-manage",data: '',render: function (data, type, row, meta) {
            		var str = '';
            		if(row['status'] != 1){
	                    str += '<a title="注册设备" href="javascript:;" onclick="sign_up(this,'+row['id']+')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe642;</i></a>';
                    }else{
                    	str += '<a title="设备信息" href="javascript:;" onclick="terminal_details(';
	                    str += "'设备信息',";
	                    str += "'{:url('queryDeviceDetail')}?id="+row['id']+"'";
	                    str += ",'',420)\"";
	                    str += 'class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6c6;</i></a>';
                    }

            		str += '<a title="编辑" href="javascript:;" onclick="terminal_edit(';
                    str += "'编辑',";
                    str += "'{:url('edit')}?id="+row['id']+"'";
                    str += ",'',500)\"";
                    str += 'class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>';

                    str += '<a title="删除" href="javascript:;" onclick="terminal_del(this,'+row['id']+')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>';

	                    
                   
                    return str;
                                
                    }
        },

    	],
    	 
	});

	$("#search_btn").click(res=>{
		request();
	});

	$("#search_down").keydown(event=>{
           if (event.which == 13){
				request();
           }
    })

	function request() {
		table.settings()[0].ajax.data = {
	    	'datemin':$('#datemin').val(),
	    	'datemax':$('#datemax').val(),
	    	'brand_id':$('#brand_id').val(),
	    	'relevance':$('#relevance').val(),
	    	'agency_id':$('#agency_id').val(),
	    	'supplier_no':$('#supplier_no').val(),
	    	'search_inpute':$('#search_inpute').val(),
	    	'status':$('#status').val()
		};
	    table.ajax.reload();
	}

});

function operate(title,url,w,h) {
	layer_show(title,url,w,h);
}

/*导入表格数据*/
function excel_data_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*导出*/
function excel_data_out(title,url,w,h) {
	// layer.confirm('<p class="c-warning">可以选择搜索条件导出</p>',function(index){
	// 	// top.location.href = url;
	// 	let datemin = $('#datemin').val();
 //    	let datemax = $('#datemax').val();
 //    	let brand_id = $('#brand_id').val();
 //    	let relevance = $('#relevance').val();
 //    	let agency_id = $('#agency_id').val();
 //    	let supplier_no = $('#supplier_no').val();
	//     let	search_inpute = $('#search_inpute').val();

	// 	window.location.href = url+'?'+'datemin='+datemin+'&datemax='+datemax+'&brand_id='+brand_id+'&relevance='+relevance+'&agency_id='+agency_id+'&supplier_no='+supplier_no+'&search_inpute='+search_inpute;

	// 		layer.msg('导出成功,正在下载', {icon: 1});
			
	
	// });

}

function member_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*产品-查看*/
function product_show(title,url,id){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}
/*产品-审核*/
function product_shenhe(obj,id){
	layer.confirm('审核文章？', {
		btn: ['通过','不通过'], 
		shade: false
	},
	function(){
		$(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="product_start(this,id)" href="javascript:;" title="申请上线">申请上线</a>');
		$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已发布</span>');
		$(obj).remove();
		layer.msg('已发布', {icon:6,time:1000});
	},
	function(){
		$(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="product_shenqing(this,id)" href="javascript:;" title="申请上线">申请上线</a>');
		$(obj).parents("tr").find(".td-status").html('<span class="label label-danger radius">未通过</span>');
		$(obj).remove();
    	layer.msg('未通过', {icon:5,time:1000});
	});	
}
/*车辆解绑*/
function product_stop(obj,id){
	layer.confirm('解除绑定',function(index){
		$.ajax({
			type: 'POST',
			url: '{:url('index/Cars/unBandCars')}',
			data:{'id':id},
			dataType: 'json',
			success: function(data){
				if(data.result == 0){

					$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="ml-5" onClick="product_start(this,'+id+')" href="javascript:;" title="绑定车辆"><i class="Hui-iconfont">&#xe603;</i></a>');
					$(obj).remove();
					layer.msg('已解绑!',{icon: 5,time:1000});
				}else{
					layer.msg(data['msg']);
				}
			},
			error:function(data) {
				console.log(data.msg);
			},
		});	
		
		
	});
}

/*车辆绑定*/
function product_start(obj,id){
	layer.confirm('绑定车辆',function(index){
		$.ajax({
			type: 'POST',
			url: '{:url('index/Cars/bandCars')}',
			data:{'id':id},
			dataType: 'json',
			success: function(data){
				if(data.result == 0){
					$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="ml-5" onClick="product_stop(this,'+id+')" href="javascript:;" title="解除绑定"><i class="Hui-iconfont">&#xe6de;</i></a>');
					$(obj).remove();
					layer.msg('已绑定!',{icon: 6,time:1000});
				}else{
					layer.msg(data['msg']);
				}
			},
			error:function(data) {
				console.log(data.msg);
			},
		});

		
	});
}

/*产品-申请上线*/
function product_shenqing(obj,id){
	$(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">待审核</span>');
	$(obj).parents("tr").find(".td-manage").html("");
	layer.msg('已提交申请，耐心等待审核!', {icon: 1,time:2000});
}

/*产品-编辑*/
function product_edit(title,url){
	var index = layer.open({
		type: 2,
		title: title,
		content: url
	});
	layer.full(index);
}

/*产品-删除*/
function terminal_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: "{:url('index/terminal/delete')}",
			data:{'id':id},
			dataType: 'json',
			success: function(data){
				if(data.code == 1){
					$(obj).parents("tr").remove();
					layer.msg('已删除!',{icon:1,time:1000});
				}else{
					layer.msg(data['msg']);
				}
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}

/*注册设备*/
function sign_up(obj,id){
	layer.confirm('确认要注册吗？',function(index){
		$.ajax({
			type:'POST',
			url: "{:url('index/terminal/registDevice')}",
			data:{
				'id':id
			},
			dataType: 'json',
			success: function(data){
				if(data.result == 1){
					str = '';
					str += '<a title="设备信息" href="javascript:;" onclick="terminal_details(';
                    str += "'设备信息',";
                    str += "'{:url('queryDeviceDetail')}?id="+id+"'";
                    str += ",'',420)\"";
                    str += 'class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6c6;</i></a>';
					$(obj).parents("tr").find(".td-manage").prepend(str);
					$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已注册</span>');
					$(obj).remove();
					layer.msg('设备注册成功!',{icon:1,time:1000});
					
				}else{
					layer.msg(data['msg']);
				}
			}
		})
	});
}

/*批量注册*/
function register(){
	var str = '';
    let obj = $(":checkbox[name='register']").each(function () {
        if( this.checked==true ){
            str += this.value;
            str += ",";
        }
    });
    if(str==''){
        layer.msg('请选择设备', {icon:5,time:1000});
    }else{
       layer.confirm('确认要注册吗？',function(index){
		$.ajax({
			type:'POST',
			url: "{:url('index/terminal/batchRegistDevice')}",
			data:{
				'id':str
			},
			dataType: 'json',
			success: function(data){
				if(data.result == 1){
					/*str = '';
					str += '<a title="设备信息" href="javascript:;" onclick="terminal_details(';
                    str += "'设备信息',";
                    str += "'{:url('queryDeviceDetail')}?id="+id+"'";
                    str += ",'',420)\"";
                    str += 'class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6c6;</i></a>';
					$(obj).parents("tr").find(".td-manage").prepend(str);
					$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已注册</span>');
					$(obj).remove();
					*/
					layer.msg(data['msg'],{icon:1,time:1000});

					setTimeout(()=>{
						window.location.replace(location.href);
					},2000)
					
				}else{
					layer.msg(data['msg']);
				}
			}
		})
	});
    }
}

/*编辑*/
function terminal_edit(title,url,w,h){
	layer_show(title,url,w,h);
}

/*查看设备信息*/
function terminal_details(title,url,w,h){
	layer_show(title,url,w,h);
}

function query(title,url,w,h){
	var str = '';
    let obj = $(":checkbox[name='register']").each(function () {
        if( this.checked==true ){
            str += this.value;
            str += ",";
        }
    });
    if(str==''){
        layer.msg('请选择设备', {icon:5,time:1000});
    }else{
        layer_show('设备变更',"{:url('index/terminal/queryDeviceDetail')}"+'?id='+str,'',250);
    }
}
</script>
</body>
</html>